package com.xiaojiang.service.impl;

import cn.dev33.satoken.util.SaResult;
import com.xiaojiang.dto.QueryCarRecordsDto;
import com.xiaojiang.dto.QueryPersonRecordsDto;
import com.xiaojiang.entity.CarAccessRecords;
import com.xiaojiang.entity.PersonAccessRecords;
import com.xiaojiang.mapper.CarRecordsMapper;
import com.xiaojiang.mapper.PersonRecordsMapper;
import com.xiaojiang.service.RecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能：
 * 作者：小江
 * 日期：2024年10月25日
 */
@Service
public class RecordsServiceImpl implements RecordsService {

    @Autowired
    private PersonRecordsMapper personRecordsMapper;

    @Autowired
    private CarRecordsMapper carRecordsMapper;
    @Override
    public SaResult queryPersonRecords(QueryPersonRecordsDto queryPersonRecordsDto) {
        List<PersonAccessRecords> personAccessRecords = personRecordsMapper.queryAllPersonRecords(queryPersonRecordsDto);
        Long total = personRecordsMapper.countAllPersonRecords();
        if (personAccessRecords == null || total == 0){
            return SaResult.error("查询失败！");
        }
        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("role","住户");
        map.put("personAccessRecords",personAccessRecords);
        return SaResult.ok("查询成功！").setData(map);
    }

    @Override
    public SaResult queryCarRecords(QueryCarRecordsDto queryCarRecordsDto) {
        List<CarAccessRecords> carAccessRecords = carRecordsMapper.queryAllCarRecords(queryCarRecordsDto);
        Long total = carRecordsMapper.countAllCarRecords();
        if (carAccessRecords == null || total == 0){
            return SaResult.error("查询失败！");
        }
        Map<String,Object> map = new HashMap<>();
        map.put("total",total);
        map.put("carAccessRecords",carAccessRecords);
        return SaResult.ok("查询成功！").setData(map);
    }
}
